package de.gwtprime.server.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;

import de.gwtprime.client.user.ACLManager.Karma;
import de.gwtprime.server.model.User2;

public class KarmaServlet extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	private static Logger logger = Logger.getLogger(KarmaServlet.class.getName());

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		
		String userId = req.getParameter("userId");
		
		long id = Long.parseLong(userId);
		
		User2 user = User2.findUser2(id);
		
		user.changeKarma(Karma.QuestionComplete.getKarma());
		resp.getWriter().print("done!");
		
		logger.info("Increased karma by "+Karma.QuestionComplete.getKarma());
		
	}
	
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
